package com.spic.business.train.certificate.service.impl;

import java.util.List;

import com.spic.business.train.trainInfo.service.ITrainInfoService;
import com.spic.business.train.trainUser.domain.TrainUser;
import com.spic.business.train.trainUser.mapper.TrainUserMapper;
import com.spic.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.spic.business.train.certificate.mapper.UserCertificateMapper;
import com.spic.business.train.certificate.domain.UserCertificate;
import com.spic.business.train.certificate.service.IUserCertificateService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 员工证书Service业务层处理
 * 
 * @author spic
 * @date 2021-10-15
 */
@Service
public class UserCertificateServiceImpl implements IUserCertificateService 
{
    @Autowired
    private UserCertificateMapper userCertificateMapper;
    @Autowired
    private TrainUserMapper trainUserMapper;
    @Autowired
    private ITrainInfoService trainInfoService;
    /**
     * 查询员工证书
     * 
     * @param id 员工证书主键
     * @return 员工证书
     */
    @Override
    public UserCertificate selectUserCertificateById(String id)
    {
        return userCertificateMapper.selectUserCertificateById(id);
    }

    /**
     * 查询员工证书列表
     * 
     * @param userCertificate 员工证书
     * @return 员工证书
     */
    @Override
    public List<UserCertificate> selectUserCertificateList(UserCertificate userCertificate)
    {
        return userCertificateMapper.selectUserCertificateList(userCertificate);
    }

    /**
     * 新增员工证书
     * 
     * @param userCertificate 员工证书
     * @return 结果
     */
    @Override
    @Transactional
    public int insertUserCertificate(UserCertificate userCertificate)
    {
        TrainUser trainUser=new TrainUser();
        trainUser.setId(userCertificate.getTrainUserId());
        trainUser.setTrainState(1);
        trainUser.setCertificateId(userCertificate.getId());
        trainUser.setJudge("0");
        trainUserMapper.updateTrainUser(trainUser);
        trainInfoService.updateTrainInfoforUserTrainEnd(trainUserMapper.selectTrainUserById(userCertificate.getTrainUserId()).getTrainInfoId());
        return userCertificateMapper.insertUserCertificate(userCertificate);
    }

    /**
     * 修改员工证书
     * 
     * @param userCertificate 员工证书
     * @return 结果
     */
    @Override
    public int updateUserCertificate(UserCertificate userCertificate)
    {
        return userCertificateMapper.updateUserCertificate(userCertificate);
    }

    /**
     * 批量删除员工证书
     * 
     * @param ids 需要删除的员工证书主键
     * @return 结果
     */
    @Override
    public int deleteUserCertificateByIds(String[] ids)
    {
        return userCertificateMapper.deleteUserCertificateByIds(ids);
    }

    /**
     * 删除员工证书信息
     * 
     * @param id 员工证书主键
     * @return 结果
     */
    @Override
    public int deleteUserCertificateById(String id)
    {
        return userCertificateMapper.deleteUserCertificateById(id);
    }
}
